package zzcltw.com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zzcltw.com.mapper.NewsMapper;
import zzcltw.com.object.News;
import zzcltw.com.service.INewsService;
import zzcltw.com.service.common.impl.BaseServiceImpl;
import zzcltw.com.util.StringUtil;


@Service("newsService")
public class NewsServiceImpl extends BaseServiceImpl implements INewsService{
	@Autowired
	private NewsMapper newsMapper;
	@Override
	public Map<String, Object> queryNewsList(Map<String, String> map) {
		List<Map<String,String>> list = newsMapper.queryNewsList(map);
		int count = newsMapper.queryNewsListCount(map);
		Map<String,Object> bean = new HashMap<>();
		bean.put("total", Integer.toString(count));
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", list);
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", ""); 
		return map1;
	}
	/**
	 * 
	 * @Title  新闻资讯详情
	 * @Description:  queryNewsDtlById
	 * @param: @param news
	 * @param: @return
	 * @return 
	 * @throws
	 * @author zzx
	 * @Date 2018年8月22日
	 */
	public Map<String,Object> queryNewsDtlById(News news){
		news.setValidStsCd("1");
		Map<String,String> bean = newsMapper.queryNewsDtlById(news);
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", null);
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", ""); 
		return map1;
	}
	@Override
	public Map<String, Object> saveNewsInfo(News news) throws Exception {
		String newsId = getSequence("t_pt_clt_news");		
		news.setNewsId(newsId);
		news.setValidStsCd("1");
		int flag = newsMapper.saveNewsInfo(news);
		/*String filePaths = news.getFilePaths();
    	String crtUserId = news.getCrtUserId();
    	if(StringUtil.isNotEmpty(filePaths)){
    		String arr[] = filePaths.split(",");
    		for(int i=0;i<arr.length;i++){
    			Map<String,String> map = new HashMap<>();
    			String fileId = getSequence("t_pt_clt_news_file");	
    			map.put("fileId", fileId);
    			map.put("newsId", newsId);
    			map.put("fileTypeCd", "01");
    			map.put("fielNm", arr[i]);
    			map.put("filePath", arr[i]);
    			map.put("crtUserId", crtUserId);
    			map.put("validStsCd", "1");
    			newsMapper.saveNewsInfoFile(map);
    		}
    	}*/
    	Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
	}

	@Override
	public Map<String, Object> updateNewsInfo(News news) throws Exception {
		String newsId = news.getNewsId();		
		int flag = newsMapper.updateNewsInfo(news);
		/*String filePaths = news.getFilePaths();
    	String crtUserId = news.getCrtUserId();
    	Map<String,String> m = new HashMap<>();
    	m.put("newsId", newsId);
    	newsMapper.delNewsInfoFile(m);
    	if(StringUtil.isNotEmpty(filePaths)){
    		String arr[] = filePaths.split(",");
    		for(int i=0;i<arr.length;i++){
    			Map<String,String> map = new HashMap<>();
    			String fileId = getSequence("t_pt_clt_news_file");	
    			map.put("fileId", fileId);
    			map.put("newsId", newsId);
    			map.put("fileTypeCd", "01");
    			map.put("fielNm", arr[i]);
    			map.put("filePath", arr[i]);
    			map.put("crtUserId", crtUserId);
    			map.put("validStsCd", "1");
    			newsMapper.saveNewsInfoFile(map);
    		}
    	}*/
    	Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
	}
	/**
	 * 删除新闻资讯
	 */
	@Override
	public Map<String, Object> delNewsInfo(Map<String,String> map) throws Exception {
		//newsMapper.delNewsInfoFile(map);
		int flag = newsMapper.delNewsInfo(map);
		Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
	}
}
